package com.alibaba.dubbo.demo.consumer;

import java.util.concurrent.TimeUnit;

import com.alibaba.dubbo.demo.DemoService;
import com.alibaba.dubbo.demo.Student;
import com.alibaba.dubbo.rpc.RpcContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Consumer {
    public static void main(String[] args) throws InterruptedException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
        context.start();
        DemoService demoService = (DemoService) context.getBean("demoService"); // get remote service proxy
        DemoService demoService2 = (DemoService) context.getBean("demoService2"); // get remote service proxy

//        while (true) {
        int fail = 0;
        for(int i=0;i<1;i++){
            try {
            	Student st = new Student();
            	st.setName("zsl");
            	st.setAge(10);
            	RpcContext.getContext().setAttachment("name2", "aaa");
            	Student st2 = demoService.sayHello(st); // call remote method
                System.out.println("=====" + st2); // get result
                //TimeUnit.MINUTES.sleep(1000);
            } catch (Throwable throwable) {
            	fail++;
            	try {
					//TimeUnit.MINUTES.sleep(1000);
				} catch (Exception e) {
					e.printStackTrace();
				}
                //throwable.printStackTrace();
            }
        }
        System.out.println("fail: " + fail);
        TimeUnit.MINUTES.sleep(1000);
    }
}
